package com.tuyrt.hi.hiitem

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.tuyrt.hi.hiitem.hiitem.HiAdapter
import com.tuyrt.hi.hiitem.hiitem.*
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val hiAdapter = HiAdapter(this)

        recycler_view.layoutManager = GridLayoutManager(this, 2)
        recycler_view.adapter = hiAdapter

        val dataSets: ArrayList<HiDataItem<*, out RecyclerView.ViewHolder>> = ArrayList()
        dataSets.add(TopTabDataItem(ItemData()))
        dataSets.add(TopBanner(ItemData()))
        dataSets.add(GridDataItem(ItemData()))
        dataSets.add(ActivityDataItem(ItemData())) //活动区域
        dataSets.add(ItemTabDataItem(ItemData())) // 商品tab栏

        for (i in 0..9) {
            if (i % 2 == 0) {
                // feeds流的视频类型
                dataSets.add(VideoDataItem(1, ItemData()))
            } else {
                // feeds流的图片类型
                dataSets.add(ImageDataItem(1, ItemData()))
            }
        }

        hiAdapter.addItems(dataSets, false)

        addFooter(hiAdapter)
    }

    private fun addFooter(hiAdapter: HiAdapter) {
        val footerView = layoutInflater.inflate(R.layout.layout_load_more, recycler_view, false)
        val btnLoadMore = footerView.findViewById<Button>(R.id.btn_load_more)
        btnLoadMore.setOnClickListener {
            Log.d("aaaa", "***************addFooter***************")
        }
        hiAdapter.addFooterView(footerView)
    }
}